﻿// // ******************************************************************
// //       /\ /|       @file       UserDataQueryHandler.cs
// //       \ V/        @brief      await29
// //       | "")       @author     Await, 285283010@qq.com
// //       /  |
// //      /  \\        @Modified   2024-11-03 19:11
// //    *(__\_\        @Copyright  Copyright (c) , 2024-11-03 11:11 Await
// // ******************************************************************

using System.Security.Authentication;
using AutomaticSubtitles.Contracts.Dto;
using AutomaticSubtitles.Service.Application.User.Queries;
using AutomaticSubtitles.Service.Domain.User;

namespace AutomaticSubtitles.Service.Application.User;

public class UserDataQueryHandler(IUserRepository repository):BaseAutoService
{
    [EventHandler]
    public async Task GetUserDataQuery(GetUserDataQuery query)
    {
        var autoUser = await repository.FindAsync(x => x.Id == query.userId && x.IsDeleted != true && x.IsFrozen != true) ?? throw new AuthenticationException(ReturnMessage(AccountError));
        query.Result = new UserLoginDto()
        {
            Id = autoUser.Id,
            UserName = autoUser.NickName,
            Roles = ["Await_Admin"],
            Buttons = []
        };
    }
}